package cn.lds.j368.dsedu.service.impl;

import cn.lds.j368.dsedu.constent.DseduConstent;
import cn.lds.j368.dsedu.dto.ResultJson;
import cn.lds.j368.dsedu.entity.Video;
import cn.lds.j368.dsedu.exceipeion.SysException;
import cn.lds.j368.dsedu.mapper.VideoMapper;
import cn.lds.j368.dsedu.service.VideoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

@Service
public class VideoServiceImpl implements VideoService {

    @Autowired
    private VideoMapper videoMapper;

    private static final Logger log = LoggerFactory.getLogger(VideoService.class);
    @Override
    public ResultJson<List<Video>> selectVideoAll() throws SysException {

        List<Video> videos = videoMapper.selectList(null);

        if (CollectionUtils.isEmpty(videos)){
            throw new SysException(DseduConstent.DseduCommonMsg.SYS_FIND_DATA_FAIL);
        }

        return ResultJson.bulidSuccess(videos);
    }

    @Override
    public ResultJson<Video> selectVideoById(Integer videoId) throws SysException {

        Video video = videoMapper.selectById(videoId);

        log.info("服务执行……");

        if (Objects.isNull(video)){
            throw new SysException(DseduConstent.DseduCommonMsg.SYS_FIND_DATA_FAIL);
        }

        return ResultJson.bulidSuccess(video);
    }
}
